import http from '../../config/request'
import echarts from 'echarts'

export default function (code, name) {
  return http('getmap_json/page', { cityno: code }).then(
    res=> {
      let geo = null
      try {
        geo = JSON.parse(res.data.mapjson)
      } catch (e) {
        geo = JSON.parse(res.data.mapjson.replace(/^./, ''))
      }
      if (!echarts.getMap(name)) echarts.registerMap(name, geo)
      return geo
    }
  )
}
